import { _decorator, Component, instantiate, Node, Prefab, v3 } from 'cc';
import { LayerBase } from './LayerBase';
import { RewardCellItem } from '../mainScene/RewardCellItem';
import { StartSceneGameMgr } from './StartSceneGameMgr';
import { AudioMgr } from '../utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('GetRewardPanel')
export class GetRewardPanel extends LayerBase {

    @property(Node)
    content: Node;
    @property(Prefab)
    rewardCellPre: Node;

    tipArr=[];
    indexCount=0;

    init(someData?: any): void {
        AudioMgr.ins.playOneShot("audio/getReward",0.6);
        this.unscheduleAllCallbacks();
        this.tipArr = [];
        this.indexCount = 0;
        this.content.removeAllChildren();

        if (someData.length&&someData.length>0) {
            someData.forEach(element => {
                let pre = instantiate(this.rewardCellPre);
                pre.setParent(this.content);
                pre.getComponent(RewardCellItem).init(element)
    
                if (element.roleType != undefined) {//如果是角色奖励，修改一下图片scale
                    pre.getChildByName("sp").setScale(v3(1, 1.3, 1))
                }
                else {
                    pre.getChildByName("sp").setScale(v3(1, 1, 1))
                }
    
                if (element.quality != undefined) {
                    let qualityName = "";
                    switch (element.quality) {
                        case 0:
                            qualityName = "普通"
                            break;
                        case 1:
                            qualityName = "稀有"
                            break;
                        case 2:
                            qualityName = "史诗"
                            break;
                        case 3:
                            qualityName = "传说"
                            break;
                    }
                    this.tipArr.push("恭喜获得：" + qualityName + "品质" + element.name+"X" + element.count);
                    // StartSceneGameMgr.ins.createWidowTip("恭喜获得：" + qualityName + "品质" + element.name);
                }
                else {
                    this.tipArr.push("恭喜获得：" + element.name + "X" + element.count);
                    // StartSceneGameMgr.ins.createWidowTip("恭喜获得：" + element.name + "X" + element.count);
                }
            });
    
        }
        else{
            let pre = instantiate(this.rewardCellPre);
            pre.setParent(this.content);
            pre.getComponent(RewardCellItem).init(someData)

            if (someData.roleType != undefined) {//如果是角色奖励，修改一下图片scale
                pre.getChildByName("sp").setScale(v3(1, 1.3, 1))
            }
            else {
                pre.getChildByName("sp").setScale(v3(1, 1, 1))
            }

            if (someData.quality != undefined) {
                let qualityName = "";
                switch (someData.quality) {
                    case 0:
                        qualityName = "普通"
                        break;
                    case 1:
                        qualityName = "稀有"
                        break;
                    case 2:
                        qualityName = "史诗"
                        break;
                    case 3:
                        qualityName = "传说"
                        break;
                }
                this.tipArr.push("恭喜获得：" + qualityName + "品质" + someData.name+"X" + someData.count);
                // StartSceneGameMgr.ins.createWidowTip("恭喜获得：" + qualityName + "品质" + element.name);
            }
            else {
                this.tipArr.push("恭喜获得：" + someData.name + "X" + someData.count);
                // StartSceneGameMgr.ins.createWidowTip("恭喜获得：" + element.name + "X" + element.count);
            }

        }
     
        this.schedule(()=>{
            StartSceneGameMgr.ins.createWidowTip(this.tipArr[this.indexCount]);
            this.indexCount+=1;
        },0.8,this.tipArr.length-1,0.5)
    }


}


